﻿using System;
using System.Collections.Generic;

namespace Blackhole.Logger
{
    public sealed class Garbage
    {
        private static Garbage instance;

        public static Garbage Instance
        {
            get
            {
                if (Garbage.instance == null) Garbage.instance = new Garbage();

                return Garbage.instance;
            }
        }

        private List<LoggerBase> attachedLoggers;

        private Garbage()
        {
            this.attachedLoggers = new List<LoggerBase>();
        }

        public void Attach(LoggerBase logger)
        {
            this.attachedLoggers.Add(logger);
        }

        public void Log(object sender, LogArguements arguements)
        {
            arguements.Logged = DateTime.Now.ToFileTime();

            arguements.Source = sender.ToString().Substring(sender.ToString().LastIndexOf('.') + 1);

            foreach (LoggerBase logger in this.attachedLoggers)
            {
                logger.Log(arguements);
            }
        }

        public void Shutdown()
        {
            foreach (LoggerBase logger in this.attachedLoggers)
            {
                logger.Stop();
            }
        }
    }
}